var mongoose=require('mongoose');
var User=mongoose.model('User',{
    name:String,
    number:Number,
    winner:Boolean,
    y:Number
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


User.update({name:'A'},{number:1101,winner:true,y:null},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    User.update({name:'B'},{number:1201,winner:false,y:0},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        User.update({name:'C'},{number:1301,winner:true,y:''},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            User.update({name:'D'},{number:1401,winner:false,y:false},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                User.update({name:'E'},{number:1501,winner:false},{upsert:true},(e,r)=>{
                    if(e)throw e;
                    console.log('Update:\n',r);

                    User.find((e,r)=>{
                        if(e)throw e;
                        console.log('\nFind All:\n',JSON.stringify(r,null,2));

                        User.find({
                            y:null
                        },(e,r)=>{
                            if(e)throw e;
                            console.log('\nFind null 无值:\n',JSON.stringify(r,null,2));


                            User.find({
                                y:{
                                    $in:[null],
                                    $exists:true
                                }
                            },(e,r)=>{
                                if(e)throw e;
                                console.log('\nFind null:\n',JSON.stringify(r,null,2));
                                process.exit(1);
                            });

                        });

                    });

                });

            });

        });

    });

});


/*
 * {field:null}
 *
 * 可以匹配：
 * 1.null本身
 * 2.字段没有值
 * */
